package org.geeks.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * CacheConfig
 * 
 * @author Geek4J
 *
 */
@EnableCaching
@Configuration
public class CacheConfig {

	@Autowired
	private RedisTemplate<Object, Object> redisTemplate;

	/**
	 * Define cache strategy
	 * 
	 * @return CacheManager
	 */
	@Bean
	public CacheManager cacheManager() {
		RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate);
		Map<String, Long> expires = new HashMap<>();

		// Test expires[1min]
		expires.put("10S", 10L);

		redisCacheManager.setExpires(expires);

		return redisCacheManager;
	}

}